import Mock from "mockjs";

Mock.setup({
  timeout: "200",
});

Mock.Random.extend({
  types: function () {
    var typePrefixs = ["Chrome", "Firefox", "Safari", "Edge"];
    return this.pick(typePrefixs);
  },
  // address: function () {
  //   var addressPrefixs = ["南京", "苏州", "常州", "无锡"];
  //   return this.pick(addressPrefixs);
  // },
  state: function () {
    var statePrefixs = ["正常", "延迟", "失败"];
    return this.pick(statePrefixs);
  },
  journal: function () {
    var journalPrefix = ["新建", "删除", "编辑", "异常"];
    return this.pick(journalPrefix);
  },
});

let { manageDatas } = Mock.mock({
  "manageDatas|40": [
    {
      "id|+1": 1,
      check: false,
      type: "@types",
      time: "2022-1-11",
      name: "@cname",
      address: " @city",
      journal: "@journal",
      state: "@state",
      duration: "一小时",
      parameter: "...",
      response: "@integer(9999,9999999)",
      abnormal: "不行了",
    },
  ],
});

// 获取列表数据方法
Mock.mock("management", "get", (option) => {
  return manageDatas;
});

// 获取单个数据id
Mock.mock("managementsigle", "post", (option) => {
  let no = parseInt(option.body);
  let index = manageDatas.findIndex((r) => r.id == no);
  return index;
});

// 删除方法
Mock.mock("managementdel", "post", (option) => {
  if (option.body) {
    manageDatas.splice(option.body, 1);
    return true;
  } else {
    return false;
  }
});


export default Mock